package com.zhoug.commonlib2.notifycation;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import com.zhoug.common2.utils.AppUtils;
import com.zhoug.commonlib2.MainActivity;
import com.zhoug.commonlib2.Params;
import com.zhoug.logger2.Logger;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @Author: zhoug
 * @Date: 2024-11-16
 * @Description:
 */
public class NotificationActivity extends AppCompatActivity {
    private static final String TAG = ">>>NotificationActivity";
    private Handler mMainHandler = new Handler(Looper.getMainLooper());

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.d(TAG, "onCreate:");
        parseIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        parseIntent(intent);
    }

    private void parseIntent(Intent intent) {
        Logger.d(TAG, "parseIntent:");
        if (null != intent) {
            String mContent = intent.getStringExtra(Params.CONTENT);
            Intent targetIntent = new Intent(this, DetailActivity.class);
            targetIntent.putExtra(Params.CONTENT, mContent);
            if (AppUtils.isActivityLaunched(this, MainActivity.class)) {
                startActivity(targetIntent);
            } else {
                Intent launchIntent = getApplication().getPackageManager().getLaunchIntentForPackage(getPackageName());
                if (launchIntent != null) {
                    launchIntent.putExtra(Params.TARGET_INTENT, targetIntent);
                    startActivity(launchIntent);
                }
            }
        }
        finish();
    }


}
